export function formatDate(date: string | Date) {
  if (!(date instanceof Date)) {
    date = new Date(date);
  }
  let ms = (+new Date() - date.getTime()) / 1000;
  if (ms === 0) {
    return '刚刚'
  } else if (ms < 60) {
    return `${ms}秒`
  } else if (ms < 60 * 60) {
    return `${Math.floor(ms / 60)}分钟`
  } else if (ms < 60 * 60 * 24) {
    return `${Math.floor(ms / 60 / 60)}小时`
  } else if (ms < 60 * 60 * 24 * 30) {
    return `${Math.floor(ms / 60 / 60 / 24)}天`
  } else if (ms < 60 * 60 * 24 * 30 * 12) {
    return `${Math.floor(ms / 60 / 60 / 24 / 30)}月`
  } else {
    return `${Math.floor(ms / 60 / 60 / 24 / 30 / 12)}年`
  }
}

export function GetDateToNewData(diffValue: number) {
  var minute = 60000;
  var hour = minute * 60;
  var day = hour * 24;
  var month = day * 30;

  var nowTime = (new Date()).getTime(); //获取当前时间戳

  var ShiJianCha = nowTime - diffValue;

  var monthC: any = ShiJianCha / month;
  var weekC: any = ShiJianCha / (7 * day);
  var dayC: any = ShiJianCha / day;
  var hourC: any = ShiJianCha / hour;
  var minC: any = ShiJianCha / minute;
  var res = '';

  if (monthC >= 12) {
    const oldTime = nowTime - diffValue      // 获取记录的时间戳
    var date = new Date(oldTime);
    res = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
  } else if (monthC >= 1) {
    res = parseInt(monthC) + "个月前";
  }
  else if (weekC >= 1) {
    res = parseInt(weekC) + "周前"
  }
  else if (dayC >= 1) {
    res = parseInt(dayC) + "天前"
  }
  else if (hourC >= 1) {
    res = parseInt(hourC) + "个小时前"
  }
  else if (minC >= 1) {
    res = parseInt(minC) + "分钟前"
  } else {
    res = "刚刚"
  }
  return res;
}
export * from './markdown/index.less'
